home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT35.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  4.1 KB  |  122 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                  Demonstration Program 35                         
  5.                                           
  6.  Loads an image using wloadblock/wloadpak/wloadcel/wloadbmp/wloadpcx
  7.  and saves the same image back out using wsaveblock, wsavepak, wsavecel,     
  8.  wsavebmp, and wsavepcx.
  9.                                           
  10.  *** PROJECT ***                                                             
  11.  This program requires the file WGT5_WC.LIB to be linked.                    
  12.                                           
  13.  *** DATA FILES ***                                                          
  14.  You must have the following data files in your executable dir:              
  15.  SAMPLE.BLK, SAMPLE.PAL                                  
  16.                                WATCOM C++ VERSION 
  17. ==============================================================================
  18. */
  19.  
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <wgt5.h>
  23.  
  24. block sample_image;    /* Contains our sample image */
  25. color pal[256];
  26. short oldmode;
  27.  
  28. short image_handle;      /* File handle used for finding file sizes */
  29.              /* Note that all files store the same image data,
  30.                 and CEL, BMP, and PCX also store the palette. */ 
  31.  
  32. void main(void)
  33. {
  34.   if ( !vgadetected () )
  35.   {
  36.     printf("Error - VGA card required for any WGT program.\n");
  37.     exit(0);
  38.   }
  39.   printf ("WGT Example #35\n\n");
  40.   printf ("Several of WGT's image formats are demonstrated by loading and creating\n");
  41.   printf ("bitmaps dynamically. Image file sizes are reported so you can compare the\n");
  42.   printf ("the compression techniques. Press a key to end the program.\n");
  43.   printf ("\n\nPress any key to continue.\n");
  44.   getch ();
  45.  
  46.   oldmode = wgetmode ();
  47.   vga256 ();
  48.  
  49.   wloadpalette("sample.pal", pal);  /* Load the palette for the image 
  50.                        formats that don't store one */
  51.   wsetpalette(0, 255, pal);
  52.  
  53.   wsavepalette ("output.pal", pal); /* Save the palette to a different file */
  54.  
  55.   wtextcolor(1);
  56.  
  57.   sample_image = wloadblock ("sample.blk");   /* Load the image */
  58.   wputblock (0, 0, sample_image, 1);          /* Display the image */
  59.   wgtprintf (0, 38, NULL, "BLK");                
  60.   wsaveblock ("output.blk", sample_image);    /* Save in BLK format */
  61.   wsavepak ("sample.pak", sample_image);      /* Save into PAK format */
  62.  
  63.   wfreeblock (sample_image);                  /* Free the image */
  64.  
  65.   sample_image = wloadpak ("sample.pak");
  66.   wputblock (50, 0, sample_image, 1);
  67.   wgtprintf (50, 38, NULL, "PAK");
  68.  
  69.   wsavecel ("sample.cel", sample_image, pal);   /* Save into CEL format */
  70.   wfreeblock (sample_image);
  71.  
  72.   sample_image = wloadcel ("sample.cel", pal);
  73.   wputblock (100, 0, sample_image, 1);
  74.   wgtprintf (100, 38, NULL, "CEL");
  75.   wsavebmp ("sample.bmp", sample_image, pal);   /* Save into BMP format */
  76.   wfreeblock (sample_image);
  77.  
  78.  sample_image = wloadbmp ("sample.bmp", pal);
  79.  wputblock (150, 0, sample_image, 1);
  80.  wgtprintf (150, 38, NULL, "BMP");
  81.  wsavepcx ("sample.pcx", sample_image, pal);    /* Save into PCX format */
  82.  wfreeblock (sample_image);
  83.  
  84.  sample_image = wloadpcx ("sample.pcx", pal);
  85.  wputblock (200, 0, sample_image, 1);
  86.  wgtprintf (200, 38, NULL, "PCX");
  87.  wfreeblock (sample_image);
  88.  
  89.  wgtprintf (0, 100, NULL, "File Sizes:");
  90.  
  91.  image_handle = open ("sample.blk", O_RDONLY);
  92.  wgtprintf (8, 108, NULL, "BLK - %lu", filelength (image_handle));
  93.  close (image_handle);
  94.  
  95.  image_handle = open ("sample.pak", O_RDONLY);
  96.  wgtprintf (8, 116, NULL, "PAK - %lu", filelength (image_handle));
  97.  close (image_handle);
  98.  unlink ("sample.pak");
  99.  
  100.  image_handle = open ("sample.cel", O_RDONLY);
  101.  wgtprintf (8, 124, NULL, "CEL - %lu", filelength (image_handle));
  102.  close (image_handle);
  103.  unlink ("sample.cel");
  104.  
  105.  image_handle = open ("sample.bmp", O_RDONLY);
  106.  wgtprintf (8, 132, NULL, "BMP - %lu", filelength (image_handle));
  107.  close (image_handle);
  108.  unlink ("sample.bmp");
  109.  
  110.  image_handle = open ("sample.pcx", O_RDONLY);
  111.  wgtprintf (8, 140, NULL, "PCX - %lu", filelength (image_handle));
  112.  close (image_handle);
  113.  unlink ("sample.pcx");
  114.  
  115.  unlink ("output.pal");
  116.  unlink ("output.blk");
  117.  
  118.  
  119.  getch ();
  120.  wsetmode (oldmode);
  121. }
  122.